package edu.nf.ch06.service;

import edu.nf.ch06.mapper.UserMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.inject.Inject;
import javax.inject.Named;

/**
 * @author wangl
 * @date 2025/4/29
 */
@Service("userService")
public class UserServiceImpl implements UserService{

    /**
     *  JSR250的@Resource注解支持标注在字段和set方法上，
     *  name属性用于指定需要注入某个bean的id
     *
     *  JSR330的@Inject注解支持标注在字段、或构造方法、set方法上，
     *  当有多个实现类的时候结合@Named注解来标识需要入注入的实现类
     */
    //@Resource(name = "userMapper")
    //@Inject
    private UserMapper userMapper;

    @Inject
    //使用@Named注解来选择注入需要的bean
    public UserServiceImpl(@Named("stuMapper") UserMapper userMapper) {
        this.userMapper = userMapper;
    }

    //@Resource(name = "userMapper")
    //@Inject
    public void setUserMapper(UserMapper userMapper) {
        this.userMapper = userMapper;
    }

    @Override
    public void add() {
        userMapper.save();
    }
}